package com.itbbfx.service.pharmacymanager.impl;


import com.itbbfx.entity.Type;
import com.itbbfx.mapper.DrugdictionaryMapper;
import com.itbbfx.mapper.TypeMapper;
import com.itbbfx.service.pharmacymanager.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class TypeServiceImpl implements TypeService {
    @Resource
    private TypeMapper typeMapper;
    @Autowired
    private DrugdictionaryMapper drugdictionaryMapper;

    @Override
    public List<Type> findAllType(Type type) {
        return typeMapper.findAllType(type);
    }

    @Override
    public String deleteType(Integer typeId) {
        if(drugdictionaryMapper.countType(typeId) > 0){
            return "请确认无药品使用该药品类型后再删除！";
        }

        if (typeMapper.deleteType(typeId) > 1) {
            return "删除成功";
        }
        return "删除失败";
    }

    @Override
    public int addType(Type type) {
        return typeMapper.addType(type);
    }


    @Override
    public int count(Type type) {
        return typeMapper.count(type);
    }
}
